/**********************************************************
 * File description:QPCRDB.h
 * Function:定义结构体用来存储从数据库不同表中查出来的每行记录
 * Current Version: 1.0.0
 * Author: 夏新宇
 * Date: 2022-09-29
 *  -----
 *  Copyright by BoKun Software.
 **********************************************************/
#ifndef QPCRDB_H
#define QPCRDB_H
#include<QString>
#include<QDate>
#include<QDataStream>

//Device结构体，对应设备管理表中的一行记录
struct Device{
    QString id;
    QString name;
    QString mac;
    QString ip;
    QString port;
    QString serial_number;
    QString status;
    QString error_message; //device表中没有此字段
    QString create_time;
    QString update_time;
    QHash<QString,QString> structToQHash(){
        QHash<QString,QString> data;
        data["name"] = name;
        data["mac"] = mac;
        data["ip"] = ip;
        data["port"] = port;
        data["serial_number"] = serial_number;
        data["status"] = status;
        return data;
    }
    void QHashToStruct(QHash<QString,QString> data){
        id = data["id"];
        name = data["name"];
        mac = data["mac"];
        ip = data["ip"];
        port = data["port"];
        serial_number = data["serial_number"];
        status = data["status"];
        create_time = data["create_time"];
        update_time = data["update_time"];
    }
};

//experiment结构体，对应实验信息配置表的一行记录
struct Experiment{
    QString experiment_id;
    QString experiment_name;
    QString user_name;
    QString coding;
    QString device_id;
    QString device_name;
    QString device_series;
    QString type;
    QString remarks;
    QString reaction_volume;
    QString is_start;
    QString is_end;
    QString create_time;
    QString update_time;
    QString experiment_remarks;
    QString plate_remarks;

    QHash<QString,QString> structToQHash(){
        QHash<QString,QString> data;
        data["experiment_name"] = experiment_name;
        data["user_name"] = user_name;
        data["coding"] = coding;
        data["device_id"] = device_id;
        data["type"] = type;
        data["remarks"] = remarks;
        data["experiment_remarks"] = experiment_remarks;
        data["plate_remarks"] = plate_remarks;
        data["reaction_volume"] = reaction_volume;
        return data;
    }

    QHash<QString,QString> structToAllQHash(){
        QHash<QString,QString> data;
        data["experiment_id"] = experiment_id;
        data["experiment_name"] = experiment_name;
        data["user_name"] = user_name;
        data["coding"] = coding;
        data["device_id"] = device_id;
        data["type"] = type;
        data["remarks"] = remarks;
        data["reaction_volume"] = reaction_volume;
        return data;
    }


    void QHashToStruct(QHash<QString,QString> data){
        experiment_id = data["experiment_id"];
        experiment_name = data["experiment_name"];
        user_name = data["user_name"];
        coding = data["coding"];
        device_id = data["device_id"];
        type = data["type"];
        remarks = data["remarks"];
        reaction_volume = data["reaction_volume"];
        is_start = data["is_start"];
        is_end = data["is_end"];
        create_time = data["create_time"];
        update_time = data["update_time"];
    }


};

//sample结构体，对应实验信息配置表的一行记录
struct Sample{
    QString id;
    QString name;
    QString color_value;
    QString type; //sample表中没有此字段
    QString remarks;
    QString create_time;
    QString update_time;

    QHash<QString,QString> structToQHash(){
        QHash<QString,QString> data;
        data["name"] = name;
        data["color_value"] = color_value;
        data["remarks"] = remarks;
        return data;
    }

    void QHashToStruct(QHash<QString,QString> data){
        id = data["id"];
        name = data["name"];
        color_value = data["color_value"];
        remarks = data["remarks"];
        create_time = data["create_time"];
        update_time = data["update_time"];
    }
};

// 序列化
inline QDataStream &operator<<(QDataStream &o,const Sample &sample)
{
    return o << sample.id << sample.name << sample.color_value << sample.type;
}
// 反序列化
inline QDataStream &operator>>(QDataStream &o,Sample &sample)
{
    return o >> sample.id >> sample.name >> sample.color_value >> sample.type;
}

//chromosome结构体，对应实验信息配置表的一行记录
struct Chromosome{
    QString id;
    QString name;
    QString wave_length;
    QString creator;
    QString type;
    QString status;
    QString create_time;
    QString update_time;

    QHash<QString,QString> structToQHash(){
        QHash<QString,QString> data;
        data["name"] = name;
        data["wave_length"] = wave_length;
        data["creator"] = creator;
        data["type"] = type;
        data["status"] = status;
        return data;
    }

    void QHashToStruct(QHash<QString,QString> data){
        id = data["id"];
        name = data["name"];
        wave_length = data["wave_length"];
        creator = data["creator"];
        type = data["type"];
        status = data["status"];
        create_time = data["create_time"];
        update_time = data["update_time"];
    }
};

//ProcedureStage结构体，对应扩增程序阶段表中的一行记录
struct ProcedureStage{
    QString id;
    QString experiment_id;
    QString name;
    QString cycle_number;
    QString stage_order;
    QString create_time;
    QString update_time;
    QHash<QString,QString> structToQHash(){
        QHash<QString,QString> data;
        data["experiment_id"] = experiment_id;
        data["name"] = name;
        data["stage_order"] = stage_order;
        data["cycle_number"] = cycle_number;
        return data;
    }

    void QHashToStruct(QHash<QString,QString> data){
        id = data["id"];
        experiment_id = data["experiment_id"];
        name = data["name"];
        cycle_number = data["cycle_number"];
        stage_order = data["stage_order"];
        create_time = data["create_time"];
        update_time = data["update_time"];
    }
};


//ProcedureStep结构体，对应扩增程序步骤表中的一行记录
struct ProcedureStep{
    QString id;
    QString stage_id;
    QString step_order;
    QString temperature;
    QString rate;
    QString duration;
    QString is_fluorescence;
    QString create_time;
    QString update_time;
    QHash<QString,QString> structToQHash(){
        QHash<QString,QString> data;
        data["stage_id"] = stage_id;
        data["step_order"] = step_order;
        data["temperature"] = temperature;
        data["rate"] = rate;
        data["duration"] = duration;
        data["is_fluorescence"] = is_fluorescence;
        return data;
    }

    void QHashToStruct(QHash<QString,QString> data){
        id = data["id"];
        stage_id = data["stage_id"];
        step_order = data["step_order"];
        temperature = data["temperature"];
        rate = data["rate"];
        duration = data["duration"];
        is_fluorescence = data["is_fluorescence"];
        create_time = data["create_time"];
        update_time = data["update_time"];
    }
};

//Target结构体，对应靶基因数据表中的一行记录
struct Target{
    QString id;
    QString name;
    QString reporter;
    QString quencher;
    QString explain;
    QString type;
    QString quantity;
    QString color;
    QString create_time;
    QString update_time;



    QHash<QString,QString> structToQHash(){
        QHash<QString,QString> data;
        data["name"] = name;
        data["reporter"] = reporter;
        data["quencher"] = quencher;
        data["explain"] = explain;
        data["type"] = type;
        data["quantity"] = quantity;
        data["color"] = color;
        return data;
    }

    QHash<QString,QString> structToAllQHash(){
        QHash<QString,QString> data;
        data["id"] = id;
        data["name"] = name;
        data["reporter"] = reporter;
        data["quencher"] = quencher;
        data["explain"] = explain;
        data["type"] = type;
        data["quantity"] = quantity;
        data["color"] = color;
        data["update_time"] = "DATETIME('now','localtime')";
        return data;
    }

    void QHashToStruct(QHash<QString,QString> data){
        id = data["id"];
        name = data["name"];
        reporter = data["reporter"];
        quencher = data["quencher"];
        explain = data["explain"];
        type = data["type"];
        quantity = data["quantity"];
        color = data["color"];
        create_time = data["create_time"];
        update_time = data["update_time"];
    }

};

// 序列化
inline QDataStream &operator<<(QDataStream &o,const Target &target)
{
    return o << target.id << target.name << target.reporter << target.quencher << target.explain << target.type << target.quantity << target.color;
}
// 反序列化
inline QDataStream &operator>>(QDataStream &o,Target &target)
{
    return o >> target.id >> target.name >> target.reporter >> target.quencher >> target.explain >> target.type >> target.quantity >> target.color;
}
#endif // QPCRDB_H
